<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="客服设置" name="kefu">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-form-item label="客服二维码" prop="qrCodeUrl">
            <image-upload v-model="form.qrCodeUrl" :limit="1" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>
          </el-form-item>

          <el-form-item label="免费查看次数" prop="qrCodeUrl">
            <el-input v-model="form.vipNum"  placeholder="请输入参数键值" />
          </el-form-item>

          <el-form-item label="退出提示图" prop="exitImg">
            <image-upload v-model="form.exitImg" :limit="1" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>
          </el-form-item>

          <el-form-item label="滚动条数" prop="housRoll">
            <el-input v-model="form.housRoll"  placeholder="请输入H5页面数据滚动条数" />
          </el-form-item>

          <el-form-item label="默认房屋图" prop="defaultImg">
            <image-upload v-model="form.defaultImg" :limit="1" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>
          </el-form-item>
        </el-form>
        <el-button type="primary" @click="submitForm">保 存</el-button>
        <!--        <el-button @click="cancel">取 消</el-button>-->
      </el-tab-pane>

      <el-tab-pane label="关于我们" name="guanyu">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-form-item label="用户协议" prop="userAgreement">
            <editor v-model="form.userAgreement" :min-height="192" />
          </el-form-item>
          <el-form-item label="隐私协议 " prop="disclaimers">
            <editor v-model="form.disclaimers" :min-height="192" />
          </el-form-item>
        </el-form>
        <el-button type="primary" @click="submitForm">保 存</el-button>
        <!--        <el-button @click="cancel">取 消</el-button>-->
      </el-tab-pane>

      <el-tab-pane label="滚动管理" name="rolls">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-form-item label="滚动开关" prop="isRoll">
            <el-switch v-model="form.isRoll" active-text="开启" inactive-text="关闭" />
          </el-form-item>
        </el-form>
        <el-button type="primary" @click="submitForm">保 存</el-button>
        <!--        <el-button @click="cancel">取 消</el-button>-->
      </el-tab-pane>

      <el-tab-pane label="合作管理" name="cooperate">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-form-item label="合作二维码" prop="cooperateImg">
              <image-upload v-model="form.cooperateImg" :limit="1" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>
            </el-form-item>
        </el-form>
        <el-button type="primary" @click="submitForm">保 存</el-button>
        <!--        <el-button @click="cancel">取 消</el-button>-->
      </el-tab-pane>

<!--      <el-tab-pane label="头像设置" name="fourth">-->
<!--        <el-form ref="form" :model="form" :rules="rules" label-width="120px">-->
<!--          <el-form-item label="名称" prop="adminName">-->
<!--            <el-input v-model="form.adminName" placeholder="请输入管理员名称"  class="input_class" />-->
<!--          </el-form-item>-->
<!--          <el-form-item label="头像 " prop="adminImg">-->
<!--            <image-upload v-model="form.adminImg" :limit="1" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>-->
<!--          </el-form-item>-->
<!--        </el-form>-->
<!--        <el-button type="primary" @click="submitForm">保 存</el-button>-->
<!--        &lt;!&ndash;        <el-button @click="cancel">取 消</el-button>&ndash;&gt;-->
<!--      </el-tab-pane>-->
<!--      <el-tab-pane label="分享设置" name="third">-->
<!--        <el-form ref="form" :model="form" :rules="rules" label-width="120px">-->
<!--          <el-form-item label="分享标题" prop="infoShareTitle">-->
<!--            <el-input v-model="form.infoShareTitle" placeholder="请输入分享标题" class="input_class" />-->
<!--          </el-form-item>-->
<!--          <el-form-item label="分享图片" prop="infoShareImg">-->
<!--            <image-upload v-model="form.infoShareImg" :limit="1" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>-->
<!--          </el-form-item>-->
<!--        </el-form>-->
<!--        <el-button type="primary" @click="submitForm">保 存</el-button>-->
<!--&lt;!&ndash;        <el-button @click="cancel">取 消</el-button>&ndash;&gt;-->
<!--      </el-tab-pane>-->
<!--      <el-tab-pane label="海报设置" name="five">-->
<!--        <el-form ref="form" :model="form" :rules="rules" label-width="120px">-->
<!--          <el-form-item label="海报名称" prop="posterName">-->
<!--            <el-input v-model="form.posterName" placeholder="请输入海报名称"  class="input_class" />-->
<!--          </el-form-item>-->
<!--          <el-form-item label="海报图片" prop="posterImg">-->
<!--            <image-upload v-model="form.posterImg" :limit="1" fileRatio="6:10" :fileType="['png','jpg','jpeg']"/>-->
<!--          </el-form-item>-->
<!--        </el-form>-->
<!--          <el-button type="primary" @click="submitForm">保 存</el-button>-->
<!--&lt;!&ndash;          <el-button @click="cancel">取 消</el-button>&ndash;&gt;-->
<!--      </el-tab-pane>-->
<!--      <el-tab-pane label="团队邀请设置" name="second">-->
<!--        <el-form ref="form" :model="form" :rules="rules" label-width="150px">-->
<!--          <el-form-item label="团队加入分享标题" prop="shareTitle">-->
<!--            <el-input v-model="form.shareTitle" placeholder="请输入分享标题" class="input_class" />-->
<!--          </el-form-item>-->
<!--          <el-form-item label="团队加入分享图片" prop="shareImg">-->
<!--            <image-upload v-model="form.shareImg" :limit="1" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>-->
<!--          </el-form-item>-->
<!--        </el-form>-->
<!--        <el-button type="primary" @click="submitForm">保 存</el-button>-->
<!--      </el-tab-pane>-->
<!--      <el-tab-pane label="团队角标设置" name="six">-->
<!--        <el-form ref="form" :model="form" :rules="rules" label-width="120px">-->
<!--          <el-row style="width:100%">-->
<!--            <el-col :span="8">-->
<!--              <el-form-item label="普通用户角标" prop="subscriptOne">-->
<!--                <image-upload v-model="form.subscriptOne" :limit="1" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :span="8">-->
<!--              <el-form-item label="团队成员角标" prop="subscriptTwo">-->
<!--                <image-upload v-model="form.subscriptTwo" :limit="1" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :span="8">-->
<!--              <el-form-item label="代理商角标" prop="subscriptThree">-->
<!--                <image-upload v-model="form.subscriptThree" :limit="1" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--          </el-row>-->
<!--        </el-form>-->
<!--        <el-button type="primary" @click="submitForm">保 存</el-button>-->
<!--&lt;!&ndash;        <el-button @click="cancel">取 消</el-button>&ndash;&gt;-->
<!--      </el-tab-pane>-->
<!--      <el-tab-pane label="开屏广告设置" name="seven">-->
<!--        <el-form ref="form" :model="form" :rules="rules" label-width="120px">-->
<!--          <el-row style="width:100%">-->
<!--            <el-col :span="8">-->
<!--              <el-form-item label="开屏广告" prop="subscriptOne">-->
<!--                <image-upload v-model="form.advertisementImg" :limit="1" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--          </el-row>-->
<!--        </el-form>-->
<!--        <el-button type="primary" @click="submitForm">保 存</el-button>-->
<!--        &lt;!&ndash;        <el-button @click="cancel">取 消</el-button>&ndash;&gt;-->
<!--      </el-tab-pane>-->
<!--      <el-tab-pane label="登录页面背景图" name="eight">-->
<!--        <el-form ref="form" :model="form" :rules="rules" label-width="120px">-->
<!--          <el-row style="width:100%">-->
<!--            <el-col :span="8">-->
<!--              <el-form-item label="背景图" prop="loginBgImg">-->
<!--                <image-upload v-model="form.loginBgImg" :limit="1" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--          </el-row>-->
<!--        </el-form>-->
<!--        <el-button type="primary" @click="submitForm">保 存</el-button>-->
<!--        &lt;!&ndash;        <el-button @click="cancel">取 消</el-button>&ndash;&gt;-->
<!--      </el-tab-pane>-->
      <el-tab-pane label="oss设置" name="oss">
        <!--        <el-form ref="form" :model="form" :rules="rules" label-width="120px">-->
        <!--          <el-form-item label="客服电话" prop="customerPhone">-->
        <!--            <el-input v-model="form.customerPhone" placeholder="请输入客服电话"  class="input_class"/>-->
        <!--          </el-form-item>-->
        <!--        </el-form>-->
        <oss />
      </el-tab-pane>
      <el-tab-pane label="个人中心设置" name="custom-menu">
        <!--        <el-form ref="form" :model="form" :rules="rules" label-width="120px">-->
        <!--          <el-form-item label="客服电话" prop="customerPhone">-->
        <!--            <el-input v-model="form.customerPhone" placeholder="请输入客服电话"  class="input_class"/>-->
        <!--          </el-form-item>-->
        <!--        </el-form>-->
        <custom-menu />
      </el-tab-pane>
    </el-tabs>
<!--    </el-dialog>-->
  </div>
</template>

<script>
import { listConfigureGlobal, getConfigureGlobal, delConfigureGlobal, addConfigureGlobal, updateConfigureGlobal } from "@/api/system/configureGlobal";
import  Oss from "@/views/system/aOss"
import  CustomMenu from "@/views/system/aCustomMenu"

export default {
  name: "ConfigureGlobal",
  components:{
    Oss,
    CustomMenu
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 全局配置表格数据
      configureGlobalList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerPhone: null,
        shareTitle: null,
        shareImg: null,
        adminName: null,
        adminImg: null,
        posterName: null,
        posterImg: null,
        subscriptOne: null,
        subscriptTwo: null,
        subscriptThree: null,
        isShow: null,
        numSoft: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      activeName: 'kefu'
    };
  },
  created() {
    // this.getList();
    this.handleUpdate(1)
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    /** 查询全局配置列表 */
    getList() {
      this.loading = true;
      listConfigureGlobal(this.queryParams).then(response => {
        this.configureGlobalList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        customerPhone: null,
        shareTitle: null,
        shareImg: null,
        adminName: null,
        adminImg: null,
        posterName: null,
        posterImg: null,
        subscriptOne: null,
        subscriptTwo: null,
        subscriptThree: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null,
        delFlag: null,
        isShow: null,
        numSoft: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加全局配置";
    },
    /** 修改按钮操作 */
    handleUpdate(id) {
      console.log(id)
      // this.reset();
      // const id = row.id || this.ids
      getConfigureGlobal(id).then(response => {
        this.form = response.data;
        console.log(this.form)
        this.open = true;
        this.title = "修改全局配置";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateConfigureGlobal(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addConfigureGlobal(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除全局配置编号为"' + ids + '"的数据项？').then(function() {
        return delConfigureGlobal(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/configureGlobal/export', {
        ...this.queryParams
      }, `configureGlobal_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
.input_class{
  width: 350px;
}
</style>
